package com.zit.service;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import com.zit.dao.DeptDAO;
import com.zit.entity.Dept;
import com.zit.entity.Teacher;

public class DeptService extends BaseService {
	
	DeptDAO deptdao = new DeptDAO();
	Session s = null;
	Transaction ta = null;
	
	
	/**
	 * 查询部门：
	 * @return
	 */
	public  List<Dept> showDeptAndTeacher(){
		List<Dept> list = new ArrayList<Dept>();
		try{
			s = getSession();
			ta = s.beginTransaction();
			list = deptdao.showDeptAndTeacher(s);
			ta.commit();
		}catch (Exception e) {
			e.printStackTrace();
		}finally{
			s.close();
		}
		return list;
		
	}
	
	
	/**
	 * 查询教师：
	 * @return
	 */
	public List<Teacher> showTeacher(){
		List<Teacher> list = new ArrayList<Teacher>();

		try {
			s = getSession();
			ta = s.beginTransaction();
			list = deptdao.selectTeacher(s);
			ta.commit();
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			s.close();
		}
		return list;
	}
	
	/**
	 * 添加部门：
	 * @param dept
	 */
	public void addDept(Dept dept){
		try {
			s = getSession();
			ta = s.beginTransaction();
			deptdao.addDept(dept, s);
			ta.commit();
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			s.close();
		}
	}
	
	/**
	 * 根据部门Id显示教师:
	 * @param id
	 * @return
	 */
	public List<Dept> showTeacher(int id){
		List<Dept> list = new ArrayList<Dept>();
		try {
			s = getSession();
			ta = s.beginTransaction();
			list  =  deptdao.showTeacher(id,s);
			ta.commit();
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			s.close();
		}
		return list;
	}
}
